package cn.wolfcode.shop.cloud.web.controller;

import cn.wolfcode.shop.cloud.common.Result;
import cn.wolfcode.shop.cloud.redis.RedisService;
import cn.wolfcode.shop.cloud.service.ISeckillService;
import cn.wolfcode.shop.cloud.util.SeckillGoodVO;
import cn.wolfcode.shop.cloud.util.SeckillKeyPrefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Map;

@RestController
@RequestMapping("/seckillGood")
public class SeckillGoodController {

    @Autowired
    private ISeckillService seckillService;

    @Autowired
    private RedisService redisService;

    @RequestMapping("/query")
    public Result query(){
        //return Result.success(seckillService.query());
        Map<String, SeckillGoodVO> stringSeckillGoodVOMap = redisService.hgetAll(SeckillKeyPrefix.SECKILL_GOOD_VO, "", SeckillGoodVO.class);
        Collection<SeckillGoodVO> values = stringSeckillGoodVOMap.values();
        return Result.success(values);
    }

    @RequestMapping("/goodDetail")
    public Result<SeckillGoodVO> goodDetail(Long seckillId){
        //SeckillGoodVO seckillGoodVO = seckillService.goodDetail(seckillId);
        SeckillGoodVO seckillGoodVO = redisService.hget(SeckillKeyPrefix.SECKILL_GOOD_VO, "", seckillId + "", SeckillGoodVO.class);
        return Result.success(seckillGoodVO);
    }
}